Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A couple of small style cleanups. #12156

Merged
merged 1 commit into from
Jun 3, 2021
Merged

A couple of small style cleanups. #12156

merged 1 commit into from
Jun 3, 2021

Conversation

colmbuckley
Copy link
Contributor

@colmbuckley colmbuckley commented May 29, 2021

In zpool_load_compat():

  • initialize l_features[] with a loop rather than a static
    initializer.

  • don't redefine system constants; use private names instead

Rationale here:

When an array is initialized using a static {foo}, only the specified
members are initialized to the provided values, the rest are
initialized to zero. While B_FALSE is of course zero, it feels
unsafe to rely on this being true forever, so I'm inclined to sacrifice
a few microseconds of runtime here and initialize using a loop.

When looking for the correct combination of system constants to use
(in open() and mmap()), I prefer to use private constants rather than
redefining system ones; due to the small chance that the system
ones might be referenced later in the file. So rather than defining
O_PATH and MAP_POPULATE, I use distinct constant names.

Signed-off-by: Colm Buckley colm@tuatha.org

@colmbuckley
Copy link
Contributor Author

@nabijaczleweli @behlendorf Continuing the conversation from #11993

In `zpool_load_compat()`:

  * initialize `l_features[]` with a loop rather than a static
    initializer.

  * don't redefine system constants; use private names instead

Rationale here:

When an array is initialized using a static {foo}, only the specified
members are initialized to the provided values, the rest are
initialized to zero. While B_FALSE is of course zero, it feels
unsafe to rely on this being true forever, so I'm inclined to sacrifice
a few microseconds of runtime here and initialize using a loop.

When looking for the correct combination of system constants to use
(in open() and mmap()), I prefer to use private constants rather than
redefining system ones; due to the small chance that the system
ones might be referenced later in the file. So rather than defining
O_PATH and MAP_POPULATE, I use distinct constant names.

Signed-off-by: Colm Buckley <colm@tuatha.org>
@jwk404 jwk404 added the Status: Code Review Needed Ready for review and testing label Jun 1, 2021
@jwk404
Copy link
Contributor

jwk404 commented Jun 2, 2021

@nabijaczleweli could you take a look?

@nabijaczleweli
Copy link
Contributor

nabijaczleweli commented Jun 2, 2021

No opinion on this. The defines are stylistic, and the loop is by definition identical to the aggregate init, so it's just more noise for no good reason, but can't not yield the same codegen, so meh.

@colmbuckley
Copy link
Contributor Author

the loop is by definition identical to the aggregate init, so it's just more noise for no good reason

With respect; they are not quite the same; boolean_t l_features[SPA_FEATURES] = {B_FALSE}; only initializes the first element to B_FALSE; it initializes the rest to zero. Obviously, B_FALSE is zero in practice, but I still feel that this is a distinction we should preserve - we're using a distinct typeset enum for a reason.

@colmbuckley
Copy link
Contributor Author

The defines are stylistic

My preference is not to redefine system constants in private source; this file is very long with dozens of contributors at least, and who knows what will eventually be added to it. The principle of least surprise would lead me to leave system constants like MAP_POPULATE alone and not redefine them midway through the file. Using new names like ZC_MMAP_FLAGS makes future surprises less likely.

@colmbuckley
Copy link
Contributor Author

colmbuckley commented Jun 2, 2021

the loop is by definition identical to the aggregate init, so it's just more noise for no good reason

With respect; they are not quite the same; boolean_t l_features[SPA_FEATURES] = {B_FALSE}; only initializes the first element to B_FALSE; it initializes the rest to zero. Obviously, B_FALSE is zero in practice, but I still feel that this is a distinction we should preserve - we're using a distinct typeset enum for a reason.

Consider also a future extension of this logic which might need an initially "all-true" array; following the static initializer pattern, a developer might be tempted to write boolean_t n_features[SPA_FEATURES] = {B_TRUE}; which would be incorrect (only the first element would be set to B_TRUE). Just trying to minimize future surprises as far as possible.

@nabijaczleweli
Copy link
Contributor

Exactly – they're identical, as guaranteed by WG14. B_FALSE and B_TRUE are just compat names for zero and not zero, since boolean_t (or "an integer type") is directly used as a conditional in most cases – to me they read as "l_features is all false" and "l_features is uninitialised, then becomes all false". The difference is purely stylistic and by definition can't not be. Hence I have no opinion: you didn't like it and feel it parses better for you if you write it as a loop, so who am I to tell you that that's wrong.

Similarly for the macros – I defined them as equivalent fallbacks, you prefer to define an explicit semantic variant. Sure, that's not how I'd write it in these particular cases, but the very fact that you did means you prefer it (for reasons I don't necessarily disagree with in general) above the activation energy of posting the patches, so I have no opinion either way; if I had to give one it'd fall under "sure, why not".

@nabijaczleweli
Copy link
Contributor

nabijaczleweli commented Jun 2, 2021

I mean, I don't see how one could be tempted to think an aggregate-initialisation of any integer type to be nonzero, but if you feel like that's an issue that someone might fall victim to for some(?) reason, then sure.

@jwk404 jwk404 added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels Jun 2, 2021
@jwk404 jwk404 merged commit f97142c into openzfs:master Jun 3, 2021
behlendorf pushed a commit to behlendorf/zfs that referenced this pull request Jun 8, 2021
In `zpool_load_compat()`:

  * initialize `l_features[]` with a loop rather than a static
    initializer.

  * don't redefine system constants; use private names instead

Rationale here:

When an array is initialized using a static {foo}, only the specified
members are initialized to the provided values, the rest are
initialized to zero. While B_FALSE is of course zero, it feels
unsafe to rely on this being true forever, so I'm inclined to sacrifice
a few microseconds of runtime here and initialize using a loop.

When looking for the correct combination of system constants to use
(in open() and mmap()), I prefer to use private constants rather than
redefining system ones; due to the small chance that the system
ones might be referenced later in the file. So rather than defining
O_PATH and MAP_POPULATE, I use distinct constant names.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Signed-off-by: Colm Buckley <colm@tuatha.org>
Closes openzfs#12156
behlendorf pushed a commit to behlendorf/zfs that referenced this pull request Jun 9, 2021
In `zpool_load_compat()`:

  * initialize `l_features[]` with a loop rather than a static
    initializer.

  * don't redefine system constants; use private names instead

Rationale here:

When an array is initialized using a static {foo}, only the specified
members are initialized to the provided values, the rest are
initialized to zero. While B_FALSE is of course zero, it feels
unsafe to rely on this being true forever, so I'm inclined to sacrifice
a few microseconds of runtime here and initialize using a loop.

When looking for the correct combination of system constants to use
(in open() and mmap()), I prefer to use private constants rather than
redefining system ones; due to the small chance that the system
ones might be referenced later in the file. So rather than defining
O_PATH and MAP_POPULATE, I use distinct constant names.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Signed-off-by: Colm Buckley <colm@tuatha.org>
Closes openzfs#12156
@colmbuckley colmbuckley deleted the enum-init branch June 15, 2021 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Accepted Ready to integrate (reviewed, tested)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants